#ifndef _UART_H_
#define _UART_H_

#include <stdio.h>

#ifndef FALSE
#define FALSE 0
#endif

#ifndef TRUE
#define TRUE 1
#endif

#ifndef BOOL
typedef unsigned char BOOL;
#endif

#ifndef BAUDX
#define BAUDX	 8		// Baud rate divisor.
#define BAUD(A) ((F_CPU/BAUDX/(A))-1)
#endif

//! Default uart baud rate.
/// This is the default speed after a uartInit() command,
/// and can be changed by using uartSetBaudRate().
#define UART_DEFAULT_BAUD_RATE	9600

// buffer memory allocation defines
// buffer sizes
#ifndef TX_BUFSZ
//! Number of bytes for uart transmit buffer.
/// Do not change this value in uart.h, but rather override
/// it with the desired value defined in your project's global.h
#define TX_BUFSZ		32
#endif
#ifndef RX_BUFSZ
//! Number of bytes for uart receive buffer.
/// Do not change this value in uart.h, but rather override
/// it with the desired value defined in your project's global.h
#define RX_BUFSZ		32
#endif


typedef struct SUARTFifo
{
	uint8_t in;
	uint8_t out;
	uint8_t size;
	uint8_t buf[1];
}
UARTFifo, *pUARTFifo;


// uart initial.
void InitUART(uint16_t ubrr);
int isTxNotEmpty( void );
int isRxNotEmpty( void );


int get_c(FILE *stream);		// Non blocking, returns -1 when empty
int get_char(FILE *stream);	// Blocking, always returns character
int put_c(char c, FILE *stream);		// Non blocking, returns -1 when full
int put_char(char c, FILE *stream);	// Blocking, always returns 0.

extern FILE serial;


#endif //_UART_H_



